unit UExecCmDetailAddEditBase;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, UAddEditBase, cxGraphics,
  cxLookAndFeels, cxLookAndFeelPainters, Vcl.Menus, dxSkinsCore,
  dxSkinOffice2016Colorful, System.ImageList, Vcl.ImgList, cxImageList,
  Vcl.StdCtrls, cxButtons, Vcl.ExtCtrls, cxControls, cxContainer, cxEdit,
  cxRadioGroup, cxGroupBox, cxCheckGroup, cxTextEdit, cxLabel, cxMaskEdit,
  cxSpinEdit, cxDropDownEdit, Uni;

type
  TfrmExecCmdDetailAddEditBase = class(TfrmAddEditBase)
    edtDelay: TcxSpinEdit;
    lblDelay: TcxLabel;
    lblOutput: TcxLabel;
    edtOutput: TcxTextEdit;
    grpOutput: TcxCheckGroup;
    grpSwitchState: TcxRadioGroup;
    lblSecond: TcxLabel;
    comDevIO: TcxComboBox;
    lblDevIO: TcxLabel;
    procedure FormShow(Sender: TObject);
    procedure comDevIOPropertiesChange(Sender: TObject);
    procedure grpOutputPropertiesChange(Sender: TObject);
  private
    { Private declarations }

    procedure MadeDevIOData;
     procedure MadeOutPutPort;
  public
    { Public declarations }
  end;

var
  frmExecCmdDetailAddEditBase: TfrmExecCmdDetailAddEditBase;

implementation

uses
  UDM;

{$R *.dfm}

procedure TfrmExecCmdDetailAddEditBase.comDevIOPropertiesChange(Sender: TObject);
begin
  inherited;

  MadeOutPutPort;
end;

procedure TfrmExecCmdDetailAddEditBase.FormShow(Sender: TObject);
begin
  inherited;

  MadeDevIOData;
end;

procedure TfrmExecCmdDetailAddEditBase.grpOutputPropertiesChange(Sender: TObject);
var
  i: Integer;
  s: string;
begin
  inherited;

  s := '';

  for i := 0 to grpOutput.Properties.Items.Count - 1 do
  begin
    if grpOutput.States[i] = cbsChecked then
      s := s + grpOutput.Properties.Items[i].Caption + ';';
  end;

  edtOutput.Text := Copy(s, 1, Length(s) - 1);
end;

procedure TfrmExecCmdDetailAddEditBase.MadeDevIOData;
var
  qry: TUniQuery;
begin
  comDevIO.Properties.Items.Clear;

  qry := TUniQuery.Create(nil);
  qry.Connection := DM.ConnSqliteDB;

  try
    with qry do
    begin
      Close;
      SQL.Text := 'select * from DevIOData where DevCtrlID=''' + IntToStr(SelectExID) + ''' order by IOID';
      Open;

      while not Eof do
      begin
        comDevIO.Properties.Items.AddObject(FieldByName('IOName').AsString, TObject(FieldByName('IOID').AsInteger));

        Next;
      end;
    end;
  finally
    qry.Free;
  end;
end;

procedure TfrmExecCmdDetailAddEditBase.MadeOutPutPort;
var
  i: Integer;
  item: TcxCheckGroupItem;
const
  PORTNUM = 16;
begin
  grpOutput.Properties.Items.Clear;

  for i := 1 to PORTNUM do
  begin
    item := grpOutput.Properties.Items.Add;
    item.Caption := IntToStr(i);
  end;
end;

end.
